package com.test;

import com.ants.common.annotation.action.Controller;
import com.ants.common.annotation.action.GET;
import com.ants.common.annotation.boot.PropertyConfiguration;
import com.ants.common.annotation.boot.ViewConfiguration;
import com.ants.common.annotation.plugin.EnableActiveMQPlugin;
import com.ants.common.annotation.plugin.EnableEhcachePlugin;
import com.ants.common.annotation.plugin.EnableSQLMapPlugin;
import com.ants.common.annotation.service.Application;
import com.ants.common.bean.JsonMap;
import com.ants.common.enums.LoadType;
import com.ants.common.enums.ViewType;
import com.ants.core.startup.Jetty;
import com.ants.plugin.template.VelocityTpl;
import com.ants.restful.render.ModelAndView;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * @author MrShun
 * @version 1.0
 * @Date 2017-11-16
 */
@Application(scanPackages = "com.test")
@PropertyConfiguration(suffix = ".do", debug = true)
@ViewConfiguration(viewType = ViewType.VELOCITY, loadPath = "/tpl")
//@DbConfiguration(dbs = {
//        //配置第一个数据源
//        @DbSource(name = "cms", url = "${db1.url}", password = "${db1.password}", sourceType = DataSourceType.DRUID)
//        //配置第二个数据源
//        , @DbSource(name = "micro", url = "${db2.url}", password = "${db2.password}")
//        //配置第三个数据源
//        , @DbSource(name = "authority", url = "${db3.url}", password = "${db3.password}")
//})
@EnableSQLMapPlugin("com/test/sql")
@EnableEhcachePlugin
@Controller
public class WebApplication {

    @Autowired
    private VelocityTpl tpl;

    @GET("/view")
    public ModelAndView test() {
        Map data = JsonMap.newJsonMap().set("name", "张三").set("age", 23);
        ModelAndView modelAndView = new ModelAndView("aa", data);
        modelAndView.put("job", "Java 开发");
        return modelAndView;
    }

    @GET("/res")
    public void res() {
        tpl.clearCache();
    }

    public static void main(String[] args) {
        Jetty.run(WebApplication.class, 80);
    }
}
